<template>
     <div class="el-main-right">
          <div class="el-main-right-con">
            <el-form
              :model="ruleForm"
              status-icon
              :rules="rules"
              ref="ruleForm"
              label-width="100px"
              class="demo-ruleForm"
            >
              <el-form-item label="姓名" prop="name">
                <el-input
                  placeholder="请输入真实姓名"
                  type="text"
                  v-model="ruleForm.name"
                  autocomplete="off"
                ></el-input>
              </el-form-item>

              <el-form-item label="身份证号" prop="idcard">
                <el-input placeholder="请输入证件号" v-model.number="ruleForm.idcard">1</el-input>
              </el-form-item>
              <el-form-item>
                <div>
                  <select>
                    <option value="使用其他有效证件">使用其他有效证件</option>
                    <option value="中国人民解放军军人身份证件">中国人民解放军军人身份证件</option>
                    <option value="港澳居民来往内地通行证">港澳居民来往内地通行证</option>
                    <option value="台湾居民来往大陆通行证">台湾居民来往大陆通行证</option>
                    <option value="中华人民共和国护照">中华人民共和国护照</option>

                  </select>
                </div>

                <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
                <el-button @click="resetForm('ruleForm')">重置</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
</template>
<script>
export default {
    data() {
    var checkAge = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("证件不能为空"));
      }
      setTimeout(() => {
        if (!Number.isInteger(value)) {
          callback(new Error("请输入数字值"));
        } else {
          if (value < 18) {
            callback(new Error("必须18位数"));
          } else {
            callback();
          }
        }
      }, 1000);
    };
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入真实姓名"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };

    return {
      ruleForm: {
        name: "",

        idcard: ""
      },
      rules: {
        name: [{ validator: validatePass, trigger: "blur" }],

        idcard: [{ validator: checkAge, trigger: "blur" }]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};

</script>
<style scoped>
.el-main-right {
  height: 500px;
  width: 500px;
  background-color: #ffffff;
  position: relative;
  margin-left: 180px;
}
.el-main-right-con {
  position: absolute;
  top: 150px;
}
</style>


